//
//  ScreenRasterOverlayScreenWindow.m
//  ScreenRaster_1
//
//  Created by Tianzhou on 08-10-30.
//  Copyright 2008 Tianzhou Software Inc.. All rights reserved.
// 
//   Licensed under the Apache License, Version 2.0 (the "License"); you may not
//   use this file except in compliance with the License.  You may obtain a copy
//   of the License at
//  
//   http://www.apache.org/licenses/LICENSE-2.0
// 
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//   License for the specific language governing permissions and limitations under
//   the License.
//

#import "ScreenRasterOverlayScreenWindow.h"
#import "ScreenRasterScrollView.h"
#import "ScreenRasterTransparentView.h"
#import "ScreenRaster.h"

@implementation ScreenRasterOverlayScreenWindow

//In Interface Builder we set CustomWindow to be the class for our window, so our own initializer is called here.
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {

#if DEBUG_MODE
	NSRect winRect = contentRect;
#else
	NSRect winRect = [ [NSScreen mainScreen] visibleFrame];
#endif
	
    //Call NSWindow's version of this function, but pass in the all-important value of NSBorderlessWindowMask
    //for the styleMask so that the window doesn't have a title bar
    NSWindow* result = [super initWithContentRect:winRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:flag];
    //Set the background color to clear so that (along with the setOpaque call below) we can see through the parts
    //of the window that we're not drawing into
#if DEBUG_MODE
    [result setBackgroundColor: [NSColor colorWithCalibratedWhite:1 alpha:0.6]];
#else
	[result setBackgroundColor: [NSColor colorWithCalibratedWhite:1 alpha:0.0]];
#endif
    //This next line pulls the window up to the front on top of other system windows.  This is how the Clock app behaves;
    //generally you wouldn't do this for windows unless you really wanted them to float above everything.
    [result setLevel: kCGNormalWindowLevel];
    //Let's start with no transparency for all drawing into the window
    //but let's turn off opaqueness so that we can see through the parts of the window that we're not drawing into
    [result setOpaque:NO];
    //and while we're at it, make sure the window has a shadow, which will automatically be the shape of our custom content.
    [result setHasShadow: YES];
	
	[result setAcceptsMouseMovedEvents:YES];
	
    return result;
}

// Custom windows that use the NSBorderlessWindowMask can't become key by default.  Therefore, controls in such windows
// won't ever be enabled by default.  Thus, we override this method to change that.
- (BOOL) canBecomeKeyWindow
{
    return YES;
}

- (void)awakeFromNib
{
	ScreenRasterScrollView *theScrollView  = [[ScreenRasterScrollView alloc] initWithFrame:[[self contentView] frame]];
	[[self contentView] addSubview:theScrollView];
	[theScrollView release];
}

@end
